//
//  TGCategoryMenu.m
//  GroupBuy
//
//  Created by wwj on 15/11/4.
//  Copyright © 2015年 wwj. All rights reserved.
//

#import "TGCategoryMenu.h"
#import "TGCategoryModel.h"
#import "TGCategoryMenuItem.h"

@interface TGCategoryMenu ()

@end

@implementation TGCategoryMenu
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *array = [TGDataTool shareDataTool].categoryArray;
        for (int index = 0; index < array.count; index++) {
            TGCategoryMenuItem *btn = [[TGCategoryMenuItem alloc] init];
            btn.model = array[index];
            btn.frame = CGRectMake(index * kBottomMenuItemW, 0, 0, 0);
            [self.scrollerView addSubview:btn];
            [btn addTarget:self action:@selector(onClickItemBtn:) forControlEvents:UIControlEventTouchUpInside];
            
            if (index == 0) {
                btn.selected = YES;
                self.itemBtn = btn;
            }
        }
        self.scrollerView.contentSize = CGSizeMake(array.count * kBottomMenuItemW, 0);
    }
    return self;
}

-(void)setSubTitle{
    self.subtitlesView.setTitleBlock = ^(NSString *title){
        [TGDataTool shareDataTool].currentCategory = title;
    };
    
    self.subtitlesView.getTitleBlock = ^(){
        return [TGDataTool shareDataTool].currentCategory;
    };
}

-(void)onSelectItemBtn:(TGBottomMenuItem *)itemBtn{
    [TGDataTool shareDataTool].currentCategory = [itemBtn titleForState:UIControlStateNormal];
}


@end
